package com.tl.khadmin.controller;
  
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; 
import org.springframework.web.bind.annotation.RestController;

import com.tl.khadmin.bean.OrderProduct;
import com.tl.khadmin.bean.SettlementBill;
import com.tl.khadmin.bean.dto.OrderRefundBillDto;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.BillIService;
import com.tl.khadmin.service.GenerateOrderBillService;
import com.tl.khadmin.util.CommonUtil;

/**
 * 账单控制器
 * @author 123
 */
@RestController
@RequestMapping(value = "/bill")
public class BillController {
	
	@Resource
	private BillIService billService;  
	
	@Autowired
	private GenerateOrderBillService generateOrderBillService;
	
	/**
	 * 测试生成周结供应商账单
	 * @return
	 */
	@RequestMapping(value = "/test/weekOrderBill")
	public void weekOrderBill() {  
		generateOrderBillService.weekOrderBill(); 
	} 
	
	@RequestMapping(value = "/test/tenDaysOrderBill")
	public void tenDaysOrderBill() {  
		generateOrderBillService.tenDaysOrderBill();
	} 
	
	@RequestMapping(value = "/test/monthOrderBill")
	public void monthOrderBill() {  
		generateOrderBillService.monthOrderBill();
	} 
	
	/**
	 * 分页查询售后退款订单账单
	 */
	@RequestMapping(value = "/orderrefund/page")
	public Map<String, Page<OrderRefundBillDto>> showOrderRefundBillByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		//只查询已生成结算账单的退款记录
		params.put("isSettlement", 1);
		return CommonUtil.returnResultCodeJson("result", billService.showOrderRefundBillByPage(session, pageNum, pageSize, params));
	}

	@RequestMapping(value = "/showbypage")
	public Map<String, Page<SettlementBill>> showBillByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", billService.showBillByPage(session, pageNum, pageSize, params));
	}
	
	@RequestMapping(value = "/order/product")
	public List<OrderProduct> listOrderProduct(Integer orderId) {  
		return billService.listOrderProduct(orderId);
	} 
	
	@RequestMapping(value = "/confirm")
	public String confirm(HttpSession session,  Integer id, Integer status) { 
		if(id == null){
			return null;
		}
		return billService.confirm(session, id, status);
	} 
	
	@RequestMapping(value = "/transfer")
	public String transfer(HttpSession session,  Integer id) { 
		if(id == null){
			return null;
		}
		return billService.transfer(session, id);
	} 
	
	@RequestMapping(value = "/detail")
	public Map<String, Object> showBillDetail(HttpSession session,  Integer id) { 
		if(id == null){
			return null;
		}
		return billService.showBillDetail(id);
	}
	
}
